/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package test;
import edu.stanford.nlp.tagger.maxent.MaxentTagger;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;



/**
 *
 * @author arifn
 */
public class MaxentTaggerMapper extends MapReduceBase
            implements Mapper<Text,Text,Text,Text> {

        // to store path to model
        String modelPath;
        //MaxentTagger tagger;

        public void configure(JobConf job){

            // create path to model
            modelPath = job.get("MaxentTagger.model");

//            try {
//                // create new instance of tagger
//                tagger = new MaxentTagger("/home/arifn/hadoop/modelUI");
//
//            } catch (IOException ex) {
//                Logger.getLogger(MaxentTaggerMapper.class.getName()).log(Level.SEVERE, null, ex);
//            } catch (ClassNotFoundException ex) {
//                Logger.getLogger(MaxentTaggerMapper.class.getName()).log(Level.SEVERE, null, ex);
//            }

        }

        public void map(Text key, Text value, OutputCollector<Text, Text> output, Reporter reporter) throws IOException {

            String line = value.toString();
            MaxentTagger tagger = null;
            try {
                tagger = new MaxentTagger("/home/arifn/hadoop/modelsmall");
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(MaxentTaggerMapper.class.getName()).log(Level.SEVERE, null, ex);
            }
            
            String taggedLine = tagger.tagString(line);

            output.collect(key, new Text(taggedLine));
        }

    }
